export const getDate = (val?:string)=>{
    if(!val) return ''
    
    try{
        return val.substring(0,10);
    }catch(ex){
        return val;
    }
    
}

/**
 * 获取发文日期
 * @param val 
 */
export const getDocCreateDate = (val?:string)=>{
    if(val){
        return getDate(val).replace('-','年').replace('-','月') + '日';
    }else{
        return ''
    }
}

/**
 * 
 * @param val 格式化日期
 */
export const formateDate = (val:Date)=>{
    var year = val.getFullYear();
    var month = val.getMonth()+1;
    var date = val.getDate();
    

    var monthStr = ""
    if(month < 10){
        monthStr = "0"+month;
    }else{
        monthStr = ""+month;
    }

    var dayStr = ""
    if(date < 10){
        dayStr = "0"+date;
    }else{
        dayStr = ""+date;
    }

    return year+"-"+monthStr+"-"+dayStr+" 00:00:00";
}

export const formateDateYMD = (val:Date)=>{
    var year = val.getFullYear();
    var month = val.getMonth()+1;
    var date = val.getDate();
    

    var monthStr = ""
    if(month < 10){
        monthStr = "0"+month;
    }else{
        monthStr = ""+month;
    }

    var dayStr = ""
    if(date < 10){
        dayStr = "0"+date;
    }else{
        dayStr = ""+date;
    }

    return year+"-"+monthStr+"-"+dayStr;
}

export const getDaysDifference = (date1:Date, date2:Date)=> {
    // 将日期转换为毫秒
    const timeDiff = Math.abs(date2.getTime() - date1.getTime());
    // 计算天数
    const diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); // 或者使用 Math.floor 根据需要
    return diffDays;
}